package com.crazyice.lee.reader;

import com.crazyice.lee.data.Student;
import lombok.extern.slf4j.Slf4j;
import org.apache.flink.streaming.api.functions.source.RichParallelSourceFunction;

import java.util.Random;

@Slf4j
public class StudentList extends RichParallelSourceFunction<Student> {
    private boolean isRun=true;

    @Override
    public void run(SourceContext<Student> sourceContext) throws Exception {
        Random random=new Random();
        int number=0;
        while (isRun){
            number++;
            Student student=new Student();
            student.setName(""+random.nextInt(10240000));
            student.setAge(16+random.nextInt(2));
            student.setPassword("password");
            student.setSex(random.nextBoolean());
            sourceContext.collect(student);
            if (number>=12000)break;
        }

    }

    @Override
    public void cancel() {
        isRun=false;
    }
}
